package com.bitjsc.server.data;

import java.util.HashMap;

public class Table {
	/**
	 * 
	 */
	private static final long serialVersionUID = 566503127691659718L;

	public HashMap<String, Player> players = new HashMap<String, Player>();

	private String name = null;

	public Table(String name) {

		this.name = name;
	}

	public void addPlayer(Player player) {

		Object[] result = {this.getName(),player.getClientID(),player.getName(),player.getLocation(),player.getMoney()};
		this.invokeAll("addTablePlayer",result);
		this.players.put(player.getClientID(), player);
		player.setCurrentTable(this);
		
		

	}

	public void removePlayer(Player player) {
		
		this.players.remove(player.getClientID());
		player.setCurrentTable(null);
		this.invokeAll("playerLeftTable",new Object[]{this.name,player.getName()});
		
		

	}

	public void invokeAll(String function, Object params[]) {

		for (String key : this.players.keySet()) {
			this.players.get(key).invoke(function, params);

		}
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	

}
